package com.aiju.cash.ui.signbank.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.ui.enter.util.EnterHelper;
import com.aiju.cash.util.ImageDialogUtil;
import com.aiju.utils.T;

import java.io.File;
/**
 * @author: 流冥
 * @date: 2017-07-13
 * @Description: 上传门店图片
 */
public class UploadShopPicActivity extends BaseTitleActivity implements View.OnClickListener {
    private ImageView shop_img;
    private ImageView shop_envir;
    private ImageView cashier_desk;
    private File shopImgFile;
    private File shopEnvirFile;
    private File cashierDeskFile;
    private int REQUEST_CODE_1 = 1;
    private int REQUEST_CODE_2 = 2;
    private int REQUEST_CODE_3 = 3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload_shop_pic);
        initView();
    }

    void initView() {
        mAiJuTitleBarView.setCenterTitle("上传门店图片");
        mAiJuTitleBarView.setRightTitle("提交");
        shop_img = (ImageView) findViewById(R.id.shop_img);
        shop_envir = (ImageView) findViewById(R.id.shop_envir);
        cashier_desk = (ImageView) findViewById(R.id.cashier_desk);
        shop_img.setOnClickListener(this);
        shop_envir.setOnClickListener(this);
        cashier_desk.setOnClickListener(this);
        mAiJuTitleBarView.getRightTextView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkInfo()) {

                }
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.shop_img) {
            ImageDialogUtil.showSelectPicDialogByRequetCode(UploadShopPicActivity.this, REQUEST_CODE_1);
        } else if (v.getId() == R.id.shop_envir) {
            ImageDialogUtil.showSelectPicDialogByRequetCode(UploadShopPicActivity.this, REQUEST_CODE_2);
        } else if (v.getId() == R.id.cashier_desk) {
            ImageDialogUtil.showSelectPicDialogByRequetCode(UploadShopPicActivity.this, REQUEST_CODE_3);
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            if (requestCode == REQUEST_CODE_1) {
                shopImgFile = EnterHelper.onActivityResultByRequestCode(shop_img, resultCode, data);
            } else if (requestCode == REQUEST_CODE_2) {
                shopEnvirFile = EnterHelper.onActivityResultByRequestCode(shop_envir, resultCode, data);
            } else if (requestCode == REQUEST_CODE_3) {
                cashierDeskFile = EnterHelper.onActivityResultByRequestCode(cashier_desk, resultCode, data);
            }
        }
    }

    boolean checkInfo() {
        if (shopImgFile == null) {
            T.ToastShort("请上传整体门店(含招牌)图片");
            return false;
        } else if (shopEnvirFile == null) {
            T.ToastShort("请上传店内环境图片");
            return false;
        } else if (cashierDeskFile == null) {
            T.ToastShort("请上传收银台图片");
            return false;
        }
        return true;
    }
}